package cn.finedo.highway.util.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description:线程池配置类
 * @author: lizheng
 * @createDate: 2023-2-1
 * @version: 1.0
 */
public class ThreadPoolConfig {

    public static final ThreadPoolExecutor pool;

    // cpu 核心线程数
    private static final int AVALIABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();

    static {
        pool = new ThreadPoolExecutor(
                20,
                20,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(200),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        pool.allowCoreThreadTimeOut(true);
    }

}

